﻿(function () {

    layui.use(["layer", "jquery", "form", "laydate", "tree"], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var laydate = layui.laydate;
        var tree = layui.tree;

        $(document).ready(function () {
            $("#btn-search-preminuOrder-OK").click(on_search_preminuOrder_OKBtn_Click);
        });

        var currentDate = moment().format("YYYY-MM-DD");
        if (moment().get("hours") < 15) {
            currentDate = moment().add(-1, "days").format("YYYY-MM-DD");
        }
        laydate.render({
            elem: '#txt-search-preminuOrder-Date',
            value: currentDate,
            isInitValue: true,
            showBottom: false
        });

        function on_search_preminuOrder_OKBtn_Click() {
            $("#Premium-Order-List").html("");
            var loadingIndex = layer.msg(addStyle("正在处理 ......"),
                { icon: 16, shade: 0.01, offset: ["25%"], time: false });
            $.ajax("/ShopManage/Order/QueryPremiumOrder", {
                method: "POST",
                data: {
                    date: $("#txt-search-preminuOrder-Date").val()
                },
                complete: function (jqXHR, textStatus) {
                    layer.close(loadingIndex);
                },
                success: function (data, textStatus, jqXHR) {
                    if (data.Success == true) {
                        var data2 = data.Data;
                        if ($.isArray(data2)) {
                            handleData(data2);
                        }
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg(addStyle("系统错误，请联系管理员！"),
                        { icon: 2, time: 3 * 1000, offset: ["25%"], closeBtn: true });
                }
            });

            function handleData(data) {
                var html = '';
                data.forEach(item => {
                    html += '<label>' + item["Name"] + ': ' + item["Amount"] + '</label>';
                });
                $("#Premium-Order-List").append(html);
            }
        }

        function addStyle(str) {
            return '<span style="font-size: 16px;">' + str + '</span>';
        }
    });

})();